<?php namespace Home\Controller; 

use Hdphp\Controller\Controller;

class PayController extends CommonController{
//	1.商品表
	private $goodsModel;
//	2.地址表
	private $addrModel;
	public function __init(){
		parent::__init();
		$this->goodsModel = new \Common\Model\Goods;
		$this->addrModel = new \Common\Model\Address;
	}
	
	public function index(){
//		订单信息
//		获得订单信息
		$postData = Q('post.');
		$data = array();
//		1.获取商品信息
		foreach ($postData['goodsid'] as $k => $v) {
			$data[$k] = $this->goodsModel->where("gid = {$v}")->field("gid,gname,sprice,inventory,listpic")->find();
		}
//		添加商品数量
		foreach ($postData['goodsnum'] as $k => $v) {
			$data[$k]['num'] = $v;	
		}
//		添加属性
		static $i = 0;
		foreach ($postData['goodsspec'] as $v) {
			$data[$i]['color'] = $v[0];
			$data[$i]['size'] = $v[1];
			$i++;
		}
//		添加属性id
		foreach ($postData['value'] as $k => $v) {
			$data[$k]['value'] = $v;
		}
//		小计
		$total_all = 0;
		foreach ($data as $k => $v) {
			$data[$k]['total'] = $v['num'] * $v['sprice'];
			$total_all = $total_all + $v['num'] * $v['sprice'];
		}
//		session_id
		if(isset($postData['session_id'])){
			foreach ($postData['session_id'] as $k => $v) {
				$data[$k]['session_id'] = $v;
			}
		}
//		分配订单信息
		View::with('data',$data);
//		分配总价
		View::with('total_all',$total_all);
//		显示用户地址
		$uid = $_SESSION['uid'];
//		获得地址信息
		$addrData = $this->addrModel->where("user_uid = {$uid}")->get();
		View::with('addrData',$addrData);
		View::make();
	}
	
}
